package org.playground.booking.dao.impl;

import org.hibernate.query.Query;
import org.playground.booking.dao.IBookingStatusDao;
import org.playground.booking.entity.BookingStatus;
import org.playground.booking.enums.BookingStatusEnum;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class BookingStatusDaoImpl extends AbstractDaoImpl<BookingStatus,Long> implements IBookingStatusDao  {
    @Override
    public BookingStatus readBookingStatusByValue(BookingStatusEnum bookingStatusEnum) {
        String hql = "from BookingStatus where status =:bookingStatus";

        Query query = this.getCurrentSession().createQuery(hql);

        query.setParameter("bookingStatus",bookingStatusEnum.getStatus());

        List<BookingStatus> result = query.list();

        return result.size()==0?null:result.get(0);
    }
}
